package com.ruoyi.web.controller.warehouse;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.warehouse.domain.LwFpWarehouse;
import com.ruoyi.warehouse.domain.LwSfpWarehouse;
import com.ruoyi.warehouse.service.ILwFpWarehouseService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 成品仓库管理Controller
 * 
 * @author sll
 * @date 2023-09-19
 */
@RestController
@RequestMapping("/fpWarehouse/fpWarehouse")
public class LwFpWarehouseController extends BaseController
{
    @Autowired
    private ILwFpWarehouseService lwFpWarehouseService;

    /**
     * 查询成品仓库管理列表
     */
    @PreAuthorize("@ss.hasPermi('fpWarehouse:fpWarehouse:list')")
    @GetMapping("/list")
    public TableDataInfo list(LwFpWarehouse lwFpWarehouse)
    {
        startPage();
        List<LwFpWarehouse> list = lwFpWarehouseService.selectLwFpWarehouseList(lwFpWarehouse);
        return getDataTable(list);
    }

    /**
     * 导出成品仓库管理列表
     */
    @PreAuthorize("@ss.hasPermi('fpWarehouse:fpWarehouse:export')")
    @Log(title = "成品仓库管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LwFpWarehouse lwFpWarehouse)
    {
        List<LwFpWarehouse> list = lwFpWarehouseService.selectLwFpWarehouseList(lwFpWarehouse);
        ExcelUtil<LwFpWarehouse> util = new ExcelUtil<LwFpWarehouse>(LwFpWarehouse.class);
        util.exportExcel(response, list, "成品仓库管理数据");
    }

    /**
     * 获取成品仓库管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('fpWarehouse:fpWarehouse:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(lwFpWarehouseService.selectLwFpWarehouseById(id));
    }

    /**
     * 新增成品仓库管理
     */
    @PreAuthorize("@ss.hasPermi('fpWarehouse:fpWarehouse:add')")
    @Log(title = "成品仓库管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LwFpWarehouse lwFpWarehouse)
    {
        return toAjax(lwFpWarehouseService.insertLwFpWarehouse(lwFpWarehouse));
    }

    /**
     * 修改成品仓库管理
     */
    @PreAuthorize("@ss.hasPermi('fpWarehouse:fpWarehouse:edit')")
    @Log(title = "成品仓库管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LwFpWarehouse lwFpWarehouse)
    {
        return toAjax(lwFpWarehouseService.updateLwFpWarehouse(lwFpWarehouse));
    }

    /**
     * 成品出入库
     */
    @PutMapping("/updateFpWarehouseQuantity")
    public AjaxResult updateFpWarehouseQuantity(@RequestBody LwFpWarehouse lwFpWarehouse)
    {
        int result = lwFpWarehouseService.updateLwFpWarehouseQuantity(lwFpWarehouse);
        if (result == -1) {
            return AjaxResult.error("参数有误");
        } else if (result == -2) {
            return AjaxResult.error("库存不足");
        } else {
            return toAjax(result);
        }
    }

    /**
     * 成品出入库
     */
    @PutMapping("/transferInventory")
    public AjaxResult transferInventory(@RequestBody LwFpWarehouse lwFpWarehouse)
    {
        int result = lwFpWarehouseService.transferInventory(lwFpWarehouse);
        if (result == -1) {
            return AjaxResult.error("参数有误");
        } else if (result == -2) {
            return AjaxResult.error("库存不足");
        } else if (result == -3) {
            return AjaxResult.error("参数有误");
        } else {
            return toAjax(result);
        }
    }

    /**
     * 删除成品仓库管理
     */
    @PreAuthorize("@ss.hasPermi('fpWarehouse:fpWarehouse:remove')")
    @Log(title = "成品仓库管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(lwFpWarehouseService.deleteLwFpWarehouseByIds(ids));
    }
}
